package win.liumian.demo.springboot.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import win.liumian.sso.filter.SsoFilter;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.servlet.FilterConfig;

/**
 * @author liumian
 * @date 2018/4/4 上午11:53
 */
@Configuration
public class WebFilterConfig {

    private SsoFilter ssoFilter;

    @PostConstruct
    public void init(){
        ssoFilter = new SsoFilter();
    }

    @PreDestroy
    public void destroy(){
        ssoFilter.destroy();
    }

    @Bean
    public FilterRegistrationBean ssoFilter(){

        FilterRegistrationBean registration = new FilterRegistrationBean();
        //注入过滤器
        //拦截规则
        registration.setFilter(ssoFilter);
        registration.addUrlPatterns("/*");
        //过滤器名称
        registration.setName("ssoFilter");
        registration.addInitParameter("domain","a.liumian.win");
        registration.addInitParameter("clientId","1");
        //是否自动注册 false 取消Filter的自动注册
        registration.setEnabled(true);
        //过滤器顺序
        registration.setOrder(1);
        return registration;
    }


}
